var sort = 1;
$('.nav-price').click(function() {
	var $arr = $('.sr-content li');
	$arr.sort(function(itemA, itemB) {
		var mathA = $(itemA).find('.sr-content-rb').find('span').text().trim();
		var mathB = $(itemB).find('.sr-content-rb').find('span').text().trim();
		return (mathA - mathB) * sort;
	})
	if (sort == 1) {
		$('.icon-xiaoyuanjiaoshengxu').css('color', '#ca141d');
		$('.icon-xiaoyuanjiaojiangxu').css('color', '#333')
	} else if (sort == -1) {
		$('.icon-xiaoyuanjiaojiangxu').css('color', '#ca141d');
		$('.icon-xiaoyuanjiaoshengxu').css('color', '#333')
	}
	sort = -sort;

	$('.sr-content').empty().append($arr);
})
$(window).scroll(function() {
 	if ($(window).scrollTop() > 0) {
 		$('.back-top').css('display', 'block');
 		$('.back-top').stop(true).animate({
 			opacity: 1
 		},300)
 	} else {
 		$('.back-top').css('display', 'none');
 		$('.back-top').stop(true, true).animate({
 			opacity: 0
 		})
 	}
 })
 $('.back-top').click(function() {
 	$('body,html').stop(true).animate({
 		scrollTop: 0
 	}, 600)
 	return false;
 })
 
 //获取分类id
 var cid=GetRequest().cid;
 //加载分类对应的商品
 $.getJSON('/api/goods/list',{cate_2nd:cid,pageIndex:1,pageSize:5},function(res){
	 if(res.status){
		  var html='';
		 res.goods.forEach(function(item,index){
			html+=`<li>
			<a href="./goodsdetail.html?id=${item.id}">
					<div class="sr-content-l"><img src="${item.img_md}" ></div>
				<div class="sr-content-r">
					<div class="sr-content-rt"><span>${item.name}</span></div>
					<div class="sr-content-rm"><span>一件能明显提升幸福感的小物件</span></div>
					<div class="sr-content-rb">￥<span>${item.price}</span></div>
				</div>
				</a>
				</li>`
			 
		 });
		 $('.sr-content').html(html);
	 }
 })